package com.mail.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.UmsAdminRoleRelationMapper;
import com.mail.dubbo.mapper.UmsRoleMenuRelationMapper;
import com.mail.model.db.UmsMenu;
import com.mail.model.db.UmsRoleMenuRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/21 17:18
 **/
@DubboService
public class UmsRoleMenuRelationApiImpl implements UmsRoleMenuRelationApi{

	@Autowired
	private UmsRoleMenuRelationMapper umsRoleMenuRelationMapper;

	/**
	 * 根据 roleIds 查询
	 *
	 * @param roles
	 * @return
	 */
	@Override
	public List<UmsRoleMenuRelation> getByRoleIds(List<Long> roles) {
		LambdaQueryWrapper<UmsRoleMenuRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.in(CollUtil.isNotEmpty(roles), UmsRoleMenuRelation::getRoleId, roles);
		return umsRoleMenuRelationMapper.selectList(wrapper);
	}

	/**
	 * 获取角色相关菜单
	 *
	 * @param roleId
	 * @return
	 */
	@Override
	public List<UmsRoleMenuRelation> getByRoleId(Long roleId) {
		LambdaQueryWrapper<UmsRoleMenuRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsRoleMenuRelation::getRoleId, roleId);
		return umsRoleMenuRelationMapper.selectList(wrapper);
	}

	/**
	 * 根据 roleId 删除 对应的数据
	 *
	 * @param roleId
	 */
	@Override
	public void removeByRoleId(Long roleId) {
		LambdaQueryWrapper<UmsRoleMenuRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsRoleMenuRelation::getRoleId, roleId);
		umsRoleMenuRelationMapper.delete(wrapper);
	}

	/**
	 * 添加
	 * @param umsRoleMenuRelation
	 */
	@Override
	public void save(UmsRoleMenuRelation umsRoleMenuRelation) {
		umsRoleMenuRelationMapper.insert(umsRoleMenuRelation);
	}
}
